--    Program: 		CAPPOIMP_ITEM_B.sql
--    Description:  Import PO ITEM B information 
--    Revision:     1st     
--    Parameter: 	
--    Created By:   Kenny Leung
--    Date:         26-Jan-2006

set doc off;      
set verify off;
set serveroutput on size 1000000;
--whenever sqlerror exit failure rollback;

declare   
   l_processed_count		number;
   l_rejected_count 		number;
   l_err_msg				varchar2(2000);
   l_err_msg_tmp			varchar2(2000);
   
   l_inventory_item_id		number;
   
   cursor cur_items_b is
      select * 
      from CRST_MTL_SYSTEM_ITEMS_B
      for update;

begin
   l_processed_count := 0;
   l_rejected_count  := 0;
   l_err_msg := '';
   
   for cur in cur_items_b loop   	
       l_err_msg_tmp := '';
       
       SELECT MTL_SYSTEM_ITEMS_B_S.NEXTVAL 
       INTO l_inventory_item_id
       FROM DUAL;
             
       update CRST_MTL_SYSTEM_ITEMS_B
       set    inventory_item_id_n = l_inventory_item_id
       where  inventory_item_id = cur.INVENTORY_ITEM_ID;
       
       begin
         -- import data
         insert into MTL_SYSTEM_ITEMS_B
         (
              INVENTORY_ITEM_ID               ,
              ORGANIZATION_ID                 ,
              LAST_UPDATE_DATE                ,
              LAST_UPDATED_BY                 ,
              CREATION_DATE                   ,
              CREATED_BY                      ,
              LAST_UPDATE_LOGIN               ,
              SUMMARY_FLAG                    ,
              ENABLED_FLAG                    ,
              START_DATE_ACTIVE               ,
              END_DATE_ACTIVE                 ,
              DESCRIPTION                     ,
              BUYER_ID                        ,
              ACCOUNTING_RULE_ID              ,
              INVOICING_RULE_ID               ,
              SEGMENT1                        ,
              SEGMENT2                        ,
              SEGMENT3                        ,
              SEGMENT4                        ,
              SEGMENT5                        ,
              SEGMENT6                        ,
              SEGMENT7                        ,
              SEGMENT8                        ,
              SEGMENT9                        ,
              SEGMENT10                       ,
              SEGMENT11                       ,
              SEGMENT12                       ,
              SEGMENT13                       ,
              SEGMENT14                       ,
              SEGMENT15                       ,
              SEGMENT16                       ,
              SEGMENT17                       ,
              SEGMENT18                       ,
              SEGMENT19                       ,
              SEGMENT20                       ,
              ATTRIBUTE_CATEGORY              ,
              ATTRIBUTE1                      ,
              ATTRIBUTE2                      ,
              ATTRIBUTE3                      ,
              ATTRIBUTE4                      ,
              ATTRIBUTE5                      ,
              ATTRIBUTE6                      ,
              ATTRIBUTE7                      ,
              ATTRIBUTE8                      ,
              ATTRIBUTE9                      ,
              ATTRIBUTE10                     ,
              ATTRIBUTE11                     ,
              ATTRIBUTE12                     ,
              ATTRIBUTE13                     ,
              ATTRIBUTE14                     ,
              ATTRIBUTE15                     ,
              PURCHASING_ITEM_FLAG            ,
              SHIPPABLE_ITEM_FLAG             ,
              CUSTOMER_ORDER_FLAG             ,
              INTERNAL_ORDER_FLAG             ,
              SERVICE_ITEM_FLAG               ,
              INVENTORY_ITEM_FLAG             ,
              ENG_ITEM_FLAG                   ,
              INVENTORY_ASSET_FLAG            ,
              PURCHASING_ENABLED_FLAG         ,
              CUSTOMER_ORDER_ENABLED_FLAG     ,
              INTERNAL_ORDER_ENABLED_FLAG     ,
              SO_TRANSACTIONS_FLAG            ,
              MTL_TRANSACTIONS_ENABLED_FLAG   ,
              STOCK_ENABLED_FLAG              ,
              BOM_ENABLED_FLAG                ,
              BUILD_IN_WIP_FLAG               ,
              REVISION_QTY_CONTROL_CODE       ,
              ITEM_CATALOG_GROUP_ID           ,
              CATALOG_STATUS_FLAG             ,
              RETURNABLE_FLAG                 ,
              DEFAULT_SHIPPING_ORG            ,
              COLLATERAL_FLAG                 ,
              TAXABLE_FLAG                    ,
              QTY_RCV_EXCEPTION_CODE          ,
              ALLOW_ITEM_DESC_UPDATE_FLAG     ,
              INSPECTION_REQUIRED_FLAG        ,
              RECEIPT_REQUIRED_FLAG           ,
              MARKET_PRICE                    ,
              HAZARD_CLASS_ID                 ,
              RFQ_REQUIRED_FLAG               ,
              QTY_RCV_TOLERANCE               ,
              LIST_PRICE_PER_UNIT             ,
              UN_NUMBER_ID                    ,
              PRICE_TOLERANCE_PERCENT         ,
              ASSET_CATEGORY_ID               ,
              ROUNDING_FACTOR                 ,
              UNIT_OF_ISSUE                   ,
              ENFORCE_SHIP_TO_LOCATION_CODE   ,
              ALLOW_SUBSTITUTE_RECEIPTS_FLAG  ,
              ALLOW_UNORDERED_RECEIPTS_FLAG   ,
              ALLOW_EXPRESS_DELIVERY_FLAG     ,
              DAYS_EARLY_RECEIPT_ALLOWED      ,
              DAYS_LATE_RECEIPT_ALLOWED       ,
              RECEIPT_DAYS_EXCEPTION_CODE     ,
              RECEIVING_ROUTING_ID            ,
              INVOICE_CLOSE_TOLERANCE         ,
              RECEIVE_CLOSE_TOLERANCE         ,
              AUTO_LOT_ALPHA_PREFIX           ,
              START_AUTO_LOT_NUMBER           ,
              LOT_CONTROL_CODE                ,
              SHELF_LIFE_CODE                 ,
              SHELF_LIFE_DAYS                 ,
              SERIAL_NUMBER_CONTROL_CODE      ,
              START_AUTO_SERIAL_NUMBER        ,
              AUTO_SERIAL_ALPHA_PREFIX        ,
              SOURCE_TYPE                     ,
              SOURCE_ORGANIZATION_ID          ,
              SOURCE_SUBINVENTORY             ,
              EXPENSE_ACCOUNT,
              ENCUMBRANCE_ACCOUNT,
              RESTRICT_SUBINVENTORIES_CODE    ,
              UNIT_WEIGHT                     ,
              WEIGHT_UOM_CODE                 ,
              VOLUME_UOM_CODE                 ,
              UNIT_VOLUME                     ,
              RESTRICT_LOCATORS_CODE          ,
              LOCATION_CONTROL_CODE           ,
              SHRINKAGE_RATE                  ,
              ACCEPTABLE_EARLY_DAYS           ,
              PLANNING_TIME_FENCE_CODE        ,
              DEMAND_TIME_FENCE_CODE          ,
              LEAD_TIME_LOT_SIZE              ,
              STD_LOT_SIZE                    ,
              CUM_MANUFACTURING_LEAD_TIME     ,
              OVERRUN_PERCENTAGE              ,
              MRP_CALCULATE_ATP_FLAG          ,
              ACCEPTABLE_RATE_INCREASE        ,
              ACCEPTABLE_RATE_DECREASE        ,
              CUMULATIVE_TOTAL_LEAD_TIME      ,
              PLANNING_TIME_FENCE_DAYS        ,
              DEMAND_TIME_FENCE_DAYS          ,
              END_ASSEMBLY_PEGGING_FLAG       ,
              REPETITIVE_PLANNING_FLAG        ,
              PLANNING_EXCEPTION_SET          ,
              BOM_ITEM_TYPE                   ,
              PICK_COMPONENTS_FLAG            ,
              REPLENISH_TO_ORDER_FLAG         ,
              BASE_ITEM_ID                    ,
              ATP_COMPONENTS_FLAG             ,
              ATP_FLAG                        ,
              FIXED_LEAD_TIME                 ,
              VARIABLE_LEAD_TIME              ,
              WIP_SUPPLY_LOCATOR_ID           ,
              WIP_SUPPLY_TYPE                 ,
              WIP_SUPPLY_SUBINVENTORY         ,
              PRIMARY_UOM_CODE                ,
              PRIMARY_UNIT_OF_MEASURE         ,
              ALLOWED_UNITS_LOOKUP_CODE       ,
              COST_OF_SALES_ACCOUNT           ,
              SALES_ACCOUNT                   ,
              DEFAULT_INCLUDE_IN_ROLLUP_FLAG  ,
              INVENTORY_ITEM_STATUS_CODE      ,
              INVENTORY_PLANNING_CODE         ,
              PLANNER_CODE                    ,
              PLANNING_MAKE_BUY_CODE          ,
              FIXED_LOT_MULTIPLIER            ,
              ROUNDING_CONTROL_TYPE           ,
              CARRYING_COST                   ,
              POSTPROCESSING_LEAD_TIME        ,
              PREPROCESSING_LEAD_TIME         ,
              FULL_LEAD_TIME                  ,
              ORDER_COST                      ,
              MRP_SAFETY_STOCK_PERCENT        ,
              MRP_SAFETY_STOCK_CODE           ,
              MIN_MINMAX_QUANTITY             ,
              MAX_MINMAX_QUANTITY             ,
              MINIMUM_ORDER_QUANTITY          ,
              FIXED_ORDER_QUANTITY            ,
              FIXED_DAYS_SUPPLY               ,
              MAXIMUM_ORDER_QUANTITY          ,
              ATP_RULE_ID                     ,
              PICKING_RULE_ID                 ,
              RESERVABLE_TYPE                 ,
              POSITIVE_MEASUREMENT_ERROR      ,
              NEGATIVE_MEASUREMENT_ERROR      ,
              ENGINEERING_ECN_CODE            ,
              ENGINEERING_ITEM_ID             ,
              ENGINEERING_DATE                ,
              SERVICE_STARTING_DELAY          ,
              VENDOR_WARRANTY_FLAG            ,
              SERVICEABLE_COMPONENT_FLAG      ,
              SERVICEABLE_PRODUCT_FLAG        ,
              BASE_WARRANTY_SERVICE_ID        ,
              PAYMENT_TERMS_ID                ,
              PREVENTIVE_MAINTENANCE_FLAG     ,
              PRIMARY_SPECIALIST_ID           ,
              SECONDARY_SPECIALIST_ID         ,
              SERVICEABLE_ITEM_CLASS_ID       ,
              TIME_BILLABLE_FLAG              ,
              MATERIAL_BILLABLE_FLAG          ,
              EXPENSE_BILLABLE_FLAG           ,
              PRORATE_SERVICE_FLAG            ,
              COVERAGE_SCHEDULE_ID            ,
              SERVICE_DURATION_PERIOD_CODE    ,
              SERVICE_DURATION                ,
              WARRANTY_VENDOR_ID              ,
              MAX_WARRANTY_AMOUNT             ,
              RESPONSE_TIME_PERIOD_CODE       ,
              RESPONSE_TIME_VALUE             ,
              NEW_REVISION_CODE               ,
              INVOICEABLE_ITEM_FLAG           ,
              TAX_CODE                        ,
              INVOICE_ENABLED_FLAG            ,
              MUST_USE_APPROVED_VENDOR_FLAG   ,
              REQUEST_ID                      ,
              PROGRAM_APPLICATION_ID          ,
              PROGRAM_ID                      ,
              PROGRAM_UPDATE_DATE             ,
              OUTSIDE_OPERATION_FLAG          ,
              OUTSIDE_OPERATION_UOM_TYPE      ,
              SAFETY_STOCK_BUCKET_DAYS        ,
              AUTO_REDUCE_MPS                 ,
              COSTING_ENABLED_FLAG            ,
              AUTO_CREATED_CONFIG_FLAG        ,
              CYCLE_COUNT_ENABLED_FLAG        ,
              ITEM_TYPE                       ,
              MODEL_CONFIG_CLAUSE_NAME        ,
              SHIP_MODEL_COMPLETE_FLAG        ,
              MRP_PLANNING_CODE               ,
              RETURN_INSPECTION_REQUIREMENT   ,
              ATO_FORECAST_CONTROL            ,
              RELEASE_TIME_FENCE_CODE         ,
              RELEASE_TIME_FENCE_DAYS         ,
              CONTAINER_ITEM_FLAG             ,
              VEHICLE_ITEM_FLAG               ,
              MAXIMUM_LOAD_WEIGHT             ,
              MINIMUM_FILL_PERCENT            ,
              CONTAINER_TYPE_CODE             ,
              INTERNAL_VOLUME                 ,
              WH_UPDATE_DATE                  ,
              PRODUCT_FAMILY_ITEM_ID          ,
              GLOBAL_ATTRIBUTE_CATEGORY       ,
              GLOBAL_ATTRIBUTE1               ,
              GLOBAL_ATTRIBUTE2               ,
              GLOBAL_ATTRIBUTE3               ,
              GLOBAL_ATTRIBUTE4               ,
              GLOBAL_ATTRIBUTE5               ,
              GLOBAL_ATTRIBUTE6               ,
              GLOBAL_ATTRIBUTE7               ,
              GLOBAL_ATTRIBUTE8               ,
              GLOBAL_ATTRIBUTE9               ,
              GLOBAL_ATTRIBUTE10              ,
              PURCHASING_TAX_CODE             ,
              OVERCOMPLETION_TOLERANCE_TYPE   ,
              OVERCOMPLETION_TOLERANCE_VALUE  ,
              EFFECTIVITY_CONTROL             ,
              CHECK_SHORTAGES_FLAG            ,
              OVER_SHIPMENT_TOLERANCE         ,
              UNDER_SHIPMENT_TOLERANCE        ,
              OVER_RETURN_TOLERANCE           ,
              UNDER_RETURN_TOLERANCE          ,
              EQUIPMENT_TYPE                  ,
              RECOVERED_PART_DISP_CODE        ,
              DEFECT_TRACKING_ON_FLAG         ,
              USAGE_ITEM_FLAG                 ,
              EVENT_FLAG                      ,
              ELECTRONIC_FLAG                 ,
              DOWNLOADABLE_FLAG               ,
              VOL_DISCOUNT_EXEMPT_FLAG        ,
              COUPON_EXEMPT_FLAG              ,
              COMMS_NL_TRACKABLE_FLAG         ,
              ASSET_CREATION_CODE             ,
              COMMS_ACTIVATION_REQD_FLAG      ,
              ORDERABLE_ON_WEB_FLAG           ,
              BACK_ORDERABLE_FLAG             ,
              WEB_STATUS                      ,
              INDIVISIBLE_FLAG                ,
              DIMENSION_UOM_CODE              ,
              UNIT_LENGTH                     ,
              UNIT_WIDTH                      ,
              UNIT_HEIGHT                     ,
              BULK_PICKED_FLAG                ,
              LOT_STATUS_ENABLED              ,
              DEFAULT_LOT_STATUS_ID           ,
              SERIAL_STATUS_ENABLED           ,
              DEFAULT_SERIAL_STATUS_ID        ,
              LOT_SPLIT_ENABLED               ,
              LOT_MERGE_ENABLED               ,
              INVENTORY_CARRY_PENALTY         ,
              OPERATION_SLACK_PENALTY         ,
              FINANCING_ALLOWED_FLAG          ,
              EAM_ITEM_TYPE                   ,
              EAM_ACTIVITY_TYPE_CODE          ,
              EAM_ACTIVITY_CAUSE_CODE         ,
              EAM_ACT_NOTIFICATION_FLAG       ,
              EAM_ACT_SHUTDOWN_STATUS         ,
              DUAL_UOM_CONTROL                ,
              SECONDARY_UOM_CODE              ,
              DUAL_UOM_DEVIATION_HIGH         ,
              DUAL_UOM_DEVIATION_LOW          ,
              CONTRACT_ITEM_TYPE_CODE         ,
              SUBSCRIPTION_DEPEND_FLAG        ,
              SERV_REQ_ENABLED_CODE           ,
              SERV_BILLING_ENABLED_FLAG       ,
              SERV_IMPORTANCE_LEVEL           ,
              PLANNED_INV_POINT_FLAG          ,
              LOT_TRANSLATE_ENABLED           ,
              DEFAULT_SO_SOURCE_TYPE          ,
              CREATE_SUPPLY_FLAG              ,
              SUBSTITUTION_WINDOW_CODE        ,
              SUBSTITUTION_WINDOW_DAYS        ,
              IB_ITEM_INSTANCE_CLASS          ,
              CONFIG_MODEL_TYPE               ,
              LOT_SUBSTITUTION_ENABLED        ,
              MINIMUM_LICENSE_QUANTITY        ,
              EAM_ACTIVITY_SOURCE_CODE        ,
              LIFECYCLE_ID                    ,
              CURRENT_PHASE_ID                ,
              OBJECT_VERSION_NUMBER           
         )
         values
         (
              l_inventory_item_id                 ,
              CAPBRIMP_MAPPING.GetOrganizationMapping(cur.ORGANIZATION_ID),
              cur.LAST_UPDATE_DATE                ,
              cur.LAST_UPDATED_BY					,
              cur.CREATION_DATE                   ,
              CAPBRIMP_MAPPING.GetUserMapping(cur.CREATED_BY),
              cur.LAST_UPDATE_LOGIN               ,
              cur.SUMMARY_FLAG                    ,
              cur.ENABLED_FLAG                    ,
              cur.START_DATE_ACTIVE               ,
              cur.END_DATE_ACTIVE                 ,
              cur.DESCRIPTION                     ,
              cur.BUYER_ID                        ,
              cur.ACCOUNTING_RULE_ID              ,
              cur.INVOICING_RULE_ID               ,
              cur.SEGMENT1                        ,
              cur.SEGMENT2                        ,
              cur.SEGMENT3                        ,
              cur.SEGMENT4                        ,
              cur.SEGMENT5                        ,
              cur.SEGMENT6                        ,
              cur.SEGMENT7                        ,
              cur.SEGMENT8                        ,
              cur.SEGMENT9                        ,
              cur.SEGMENT10                       ,
              cur.SEGMENT11                       ,
              cur.SEGMENT12                       ,
              cur.SEGMENT13                       ,
              cur.SEGMENT14                       ,
              cur.SEGMENT15                       ,
              cur.SEGMENT16                       ,
              cur.SEGMENT17                       ,
              cur.SEGMENT18                       ,
              cur.SEGMENT19                       ,
              cur.SEGMENT20                       ,
              cur.ATTRIBUTE_CATEGORY              ,
              cur.ATTRIBUTE1                      ,
              cur.ATTRIBUTE2                      ,
              cur.ATTRIBUTE3                      ,
              cur.ATTRIBUTE4                      ,
              cur.ATTRIBUTE5                      ,
              cur.ATTRIBUTE6                      ,
              cur.ATTRIBUTE7                      ,
              cur.ATTRIBUTE8                      ,
              cur.ATTRIBUTE9                      ,
              cur.ATTRIBUTE10                     ,
              cur.ATTRIBUTE11                     ,
              cur.ATTRIBUTE12                     ,
              cur.ATTRIBUTE13                     ,
              cur.ATTRIBUTE14                     ,
              cur.ATTRIBUTE15                     ,
              cur.PURCHASING_ITEM_FLAG            ,
              cur.SHIPPABLE_ITEM_FLAG             ,
              cur.CUSTOMER_ORDER_FLAG             ,
              cur.INTERNAL_ORDER_FLAG             ,
              cur.SERVICE_ITEM_FLAG               ,
              cur.INVENTORY_ITEM_FLAG             ,
              cur.ENG_ITEM_FLAG                   ,
              cur.INVENTORY_ASSET_FLAG            ,
              cur.PURCHASING_ENABLED_FLAG         ,
              cur.CUSTOMER_ORDER_ENABLED_FLAG     ,
              cur.INTERNAL_ORDER_ENABLED_FLAG     ,
              cur.SO_TRANSACTIONS_FLAG            ,
              cur.MTL_TRANSACTIONS_ENABLED_FLAG   ,
              cur.STOCK_ENABLED_FLAG              ,
              cur.BOM_ENABLED_FLAG                ,
              cur.BUILD_IN_WIP_FLAG               ,
              cur.REVISION_QTY_CONTROL_CODE       ,
              cur.ITEM_CATALOG_GROUP_ID           ,
              cur.CATALOG_STATUS_FLAG             ,
              cur.RETURNABLE_FLAG                 ,
              cur.DEFAULT_SHIPPING_ORG            ,
              cur.COLLATERAL_FLAG                 ,
              cur.TAXABLE_FLAG                    ,
              cur.QTY_RCV_EXCEPTION_CODE          ,
              cur.ALLOW_ITEM_DESC_UPDATE_FLAG     ,
              cur.INSPECTION_REQUIRED_FLAG        ,
              cur.RECEIPT_REQUIRED_FLAG           ,
              cur.MARKET_PRICE                    ,
              cur.HAZARD_CLASS_ID                 ,
              cur.RFQ_REQUIRED_FLAG               ,
              cur.QTY_RCV_TOLERANCE               ,
              cur.LIST_PRICE_PER_UNIT             ,
              cur.UN_NUMBER_ID                    ,
              cur.PRICE_TOLERANCE_PERCENT         ,
              cur.ASSET_CATEGORY_ID               ,
              cur.ROUNDING_FACTOR                 ,
              cur.UNIT_OF_ISSUE                   ,
              cur.ENFORCE_SHIP_TO_LOCATION_CODE   ,
              cur.ALLOW_SUBSTITUTE_RECEIPTS_FLAG  ,
              cur.ALLOW_UNORDERED_RECEIPTS_FLAG   ,
              cur.ALLOW_EXPRESS_DELIVERY_FLAG     ,
              cur.DAYS_EARLY_RECEIPT_ALLOWED      ,
              cur.DAYS_LATE_RECEIPT_ALLOWED       ,
              cur.RECEIPT_DAYS_EXCEPTION_CODE     ,
              cur.RECEIVING_ROUTING_ID            ,
              cur.INVOICE_CLOSE_TOLERANCE         ,
              cur.RECEIVE_CLOSE_TOLERANCE         ,
              cur.AUTO_LOT_ALPHA_PREFIX           ,
              cur.START_AUTO_LOT_NUMBER           ,
              cur.LOT_CONTROL_CODE                ,
              cur.SHELF_LIFE_CODE                 ,
              cur.SHELF_LIFE_DAYS                 ,
              cur.SERIAL_NUMBER_CONTROL_CODE      ,
              cur.START_AUTO_SERIAL_NUMBER        ,
              cur.AUTO_SERIAL_ALPHA_PREFIX        ,
              cur.SOURCE_TYPE                     ,
              CAPBRIMP_MAPPING.GetOrganizationMapping(cur.SOURCE_ORGANIZATION_ID),
              cur.SOURCE_SUBINVENTORY             ,
              CAPBRIMP_MAPPING.GetCCIDMapping(cur.EXPENSE_ACCOUNT),
              CAPBRIMP_MAPPING.GetCCIDMapping(cur.ENCUMBRANCE_ACCOUNT),
              cur.RESTRICT_SUBINVENTORIES_CODE    ,
              cur.UNIT_WEIGHT                     ,
              cur.WEIGHT_UOM_CODE                 ,
              cur.VOLUME_UOM_CODE                 ,
              cur.UNIT_VOLUME                     ,
              cur.RESTRICT_LOCATORS_CODE          ,
              cur.LOCATION_CONTROL_CODE           ,
              cur.SHRINKAGE_RATE                  ,
              cur.ACCEPTABLE_EARLY_DAYS           ,
              cur.PLANNING_TIME_FENCE_CODE        ,
              cur.DEMAND_TIME_FENCE_CODE          ,
              cur.LEAD_TIME_LOT_SIZE              ,
              cur.STD_LOT_SIZE                    ,
              cur.CUM_MANUFACTURING_LEAD_TIME     ,
              cur.OVERRUN_PERCENTAGE              ,
              cur.MRP_CALCULATE_ATP_FLAG          ,
              cur.ACCEPTABLE_RATE_INCREASE        ,
              cur.ACCEPTABLE_RATE_DECREASE        ,
              cur.CUMULATIVE_TOTAL_LEAD_TIME      ,
              cur.PLANNING_TIME_FENCE_DAYS        ,
              cur.DEMAND_TIME_FENCE_DAYS          ,
              cur.END_ASSEMBLY_PEGGING_FLAG       ,
              cur.REPETITIVE_PLANNING_FLAG        ,
              cur.PLANNING_EXCEPTION_SET          ,
              cur.BOM_ITEM_TYPE                   ,
              cur.PICK_COMPONENTS_FLAG            ,
              cur.REPLENISH_TO_ORDER_FLAG         ,
              cur.BASE_ITEM_ID                    ,
              cur.ATP_COMPONENTS_FLAG             ,
              cur.ATP_FLAG                        ,
              cur.FIXED_LEAD_TIME                 ,
              cur.VARIABLE_LEAD_TIME              ,
              cur.WIP_SUPPLY_LOCATOR_ID           ,
              cur.WIP_SUPPLY_TYPE                 ,
              cur.WIP_SUPPLY_SUBINVENTORY         ,
              cur.PRIMARY_UOM_CODE                ,
              cur.PRIMARY_UNIT_OF_MEASURE         ,
              cur.ALLOWED_UNITS_LOOKUP_CODE       ,
              CAPBRIMP_MAPPING.GetCCIDMapping(cur.COST_OF_SALES_ACCOUNT),
              CAPBRIMP_MAPPING.GetCCIDMapping(cur.SALES_ACCOUNT),
              cur.DEFAULT_INCLUDE_IN_ROLLUP_FLAG  ,
              cur.INVENTORY_ITEM_STATUS_CODE      ,
              cur.INVENTORY_PLANNING_CODE         ,
              cur.PLANNER_CODE                    ,
              cur.PLANNING_MAKE_BUY_CODE          ,
              cur.FIXED_LOT_MULTIPLIER            ,
              cur.ROUNDING_CONTROL_TYPE           ,
              cur.CARRYING_COST                   ,
              cur.POSTPROCESSING_LEAD_TIME        ,
              cur.PREPROCESSING_LEAD_TIME         ,
              cur.FULL_LEAD_TIME                  ,
              cur.ORDER_COST                      ,
              cur.MRP_SAFETY_STOCK_PERCENT        ,
              cur.MRP_SAFETY_STOCK_CODE           ,
              cur.MIN_MINMAX_QUANTITY             ,
              cur.MAX_MINMAX_QUANTITY             ,
              cur.MINIMUM_ORDER_QUANTITY          ,
              cur.FIXED_ORDER_QUANTITY            ,
              cur.FIXED_DAYS_SUPPLY               ,
              cur.MAXIMUM_ORDER_QUANTITY          ,
              cur.ATP_RULE_ID                     ,
              cur.PICKING_RULE_ID                 ,
              cur.RESERVABLE_TYPE                 ,
              cur.POSITIVE_MEASUREMENT_ERROR      ,
              cur.NEGATIVE_MEASUREMENT_ERROR      ,
              cur.ENGINEERING_ECN_CODE            ,
              cur.ENGINEERING_ITEM_ID             ,
              cur.ENGINEERING_DATE                ,
              cur.SERVICE_STARTING_DELAY          ,
              cur.VENDOR_WARRANTY_FLAG            ,
              cur.SERVICEABLE_COMPONENT_FLAG      ,
              cur.SERVICEABLE_PRODUCT_FLAG        ,
              cur.BASE_WARRANTY_SERVICE_ID        ,
              cur.PAYMENT_TERMS_ID                ,
              cur.PREVENTIVE_MAINTENANCE_FLAG     ,
              cur.PRIMARY_SPECIALIST_ID           ,
              cur.SECONDARY_SPECIALIST_ID         ,
              cur.SERVICEABLE_ITEM_CLASS_ID       ,
              cur.TIME_BILLABLE_FLAG              ,
              cur.MATERIAL_BILLABLE_FLAG          ,
              cur.EXPENSE_BILLABLE_FLAG           ,
              cur.PRORATE_SERVICE_FLAG            ,
              cur.COVERAGE_SCHEDULE_ID            ,
              cur.SERVICE_DURATION_PERIOD_CODE    ,
              cur.SERVICE_DURATION                ,
              cur.WARRANTY_VENDOR_ID              ,
              cur.MAX_WARRANTY_AMOUNT             ,
              cur.RESPONSE_TIME_PERIOD_CODE       ,
              cur.RESPONSE_TIME_VALUE             ,
              cur.NEW_REVISION_CODE               ,
              cur.INVOICEABLE_ITEM_FLAG           ,
              cur.TAX_CODE                        ,
              cur.INVOICE_ENABLED_FLAG            ,
              cur.MUST_USE_APPROVED_VENDOR_FLAG   ,
              cur.REQUEST_ID                      ,
              cur.PROGRAM_APPLICATION_ID          ,
              cur.PROGRAM_ID                      ,
              cur.PROGRAM_UPDATE_DATE             ,
              cur.OUTSIDE_OPERATION_FLAG          ,
              cur.OUTSIDE_OPERATION_UOM_TYPE      ,
              cur.SAFETY_STOCK_BUCKET_DAYS        ,
              cur.AUTO_REDUCE_MPS                 ,
              cur.COSTING_ENABLED_FLAG            ,
              cur.AUTO_CREATED_CONFIG_FLAG        ,
              cur.CYCLE_COUNT_ENABLED_FLAG        ,
              cur.ITEM_TYPE                       ,
              cur.MODEL_CONFIG_CLAUSE_NAME        ,
              cur.SHIP_MODEL_COMPLETE_FLAG        ,
              cur.MRP_PLANNING_CODE               ,
              cur.RETURN_INSPECTION_REQUIREMENT   ,
              cur.ATO_FORECAST_CONTROL            ,
              cur.RELEASE_TIME_FENCE_CODE         ,
              cur.RELEASE_TIME_FENCE_DAYS         ,
              cur.CONTAINER_ITEM_FLAG             ,
              cur.VEHICLE_ITEM_FLAG               ,
              cur.MAXIMUM_LOAD_WEIGHT             ,
              cur.MINIMUM_FILL_PERCENT            ,
              cur.CONTAINER_TYPE_CODE             ,
              cur.INTERNAL_VOLUME                 ,
              cur.WH_UPDATE_DATE                  ,
              cur.PRODUCT_FAMILY_ITEM_ID          ,
              cur.GLOBAL_ATTRIBUTE_CATEGORY       ,
              cur.GLOBAL_ATTRIBUTE1               ,
              cur.GLOBAL_ATTRIBUTE2               ,
              cur.GLOBAL_ATTRIBUTE3               ,
              cur.GLOBAL_ATTRIBUTE4               ,
              cur.GLOBAL_ATTRIBUTE5               ,
              cur.GLOBAL_ATTRIBUTE6               ,
              cur.GLOBAL_ATTRIBUTE7               ,
              cur.GLOBAL_ATTRIBUTE8               ,
              cur.GLOBAL_ATTRIBUTE9               ,
              cur.GLOBAL_ATTRIBUTE10              ,
              cur.PURCHASING_TAX_CODE             ,
              cur.OVERCOMPLETION_TOLERANCE_TYPE   ,
              cur.OVERCOMPLETION_TOLERANCE_VALUE  ,
              cur.EFFECTIVITY_CONTROL             ,
              cur.CHECK_SHORTAGES_FLAG            ,
              cur.OVER_SHIPMENT_TOLERANCE         ,
              cur.UNDER_SHIPMENT_TOLERANCE        ,
              cur.OVER_RETURN_TOLERANCE           ,
              cur.UNDER_RETURN_TOLERANCE          ,
              cur.EQUIPMENT_TYPE                  ,
              cur.RECOVERED_PART_DISP_CODE        ,
              cur.DEFECT_TRACKING_ON_FLAG         ,
              cur.USAGE_ITEM_FLAG                 ,
              cur.EVENT_FLAG                      ,
              cur.ELECTRONIC_FLAG                 ,
              cur.DOWNLOADABLE_FLAG               ,
              cur.VOL_DISCOUNT_EXEMPT_FLAG        ,
              cur.COUPON_EXEMPT_FLAG              ,
              cur.COMMS_NL_TRACKABLE_FLAG         ,
              cur.ASSET_CREATION_CODE             ,
              cur.COMMS_ACTIVATION_REQD_FLAG      ,
              cur.ORDERABLE_ON_WEB_FLAG           ,
              cur.BACK_ORDERABLE_FLAG             ,
              cur.WEB_STATUS                      ,
              cur.INDIVISIBLE_FLAG                ,
              cur.DIMENSION_UOM_CODE              ,
              cur.UNIT_LENGTH                     ,
              cur.UNIT_WIDTH                      ,
              cur.UNIT_HEIGHT                     ,
              cur.BULK_PICKED_FLAG                ,
              cur.LOT_STATUS_ENABLED              ,
              cur.DEFAULT_LOT_STATUS_ID           ,
              cur.SERIAL_STATUS_ENABLED           ,
              cur.DEFAULT_SERIAL_STATUS_ID        ,
              cur.LOT_SPLIT_ENABLED               ,
              cur.LOT_MERGE_ENABLED               ,
              cur.INVENTORY_CARRY_PENALTY         ,
              cur.OPERATION_SLACK_PENALTY         ,
              cur.FINANCING_ALLOWED_FLAG          ,
              cur.EAM_ITEM_TYPE                   ,
              cur.EAM_ACTIVITY_TYPE_CODE          ,
              cur.EAM_ACTIVITY_CAUSE_CODE         ,
              cur.EAM_ACT_NOTIFICATION_FLAG       ,
              cur.EAM_ACT_SHUTDOWN_STATUS         ,
              cur.DUAL_UOM_CONTROL                ,
              cur.SECONDARY_UOM_CODE              ,
              cur.DUAL_UOM_DEVIATION_HIGH         ,
              cur.DUAL_UOM_DEVIATION_LOW          ,
              cur.CONTRACT_ITEM_TYPE_CODE         ,
              cur.SUBSCRIPTION_DEPEND_FLAG        ,
              cur.SERV_REQ_ENABLED_CODE           ,
              cur.SERV_BILLING_ENABLED_FLAG       ,
              cur.SERV_IMPORTANCE_LEVEL           ,
              cur.PLANNED_INV_POINT_FLAG          ,
              cur.LOT_TRANSLATE_ENABLED           ,
              cur.DEFAULT_SO_SOURCE_TYPE          ,
              cur.CREATE_SUPPLY_FLAG              ,
              cur.SUBSTITUTION_WINDOW_CODE        ,
              cur.SUBSTITUTION_WINDOW_DAYS        ,
              cur.IB_ITEM_INSTANCE_CLASS          ,
              cur.CONFIG_MODEL_TYPE               ,
              cur.LOT_SUBSTITUTION_ENABLED        ,
              cur.MINIMUM_LICENSE_QUANTITY        ,
              cur.EAM_ACTIVITY_SOURCE_CODE        ,
              cur.LIFECYCLE_ID                    ,
              cur.CURRENT_PHASE_ID                ,
              cur.OBJECT_VERSION_NUMBER           
         );  
       exception
         when others then
       	 l_err_msg_tmp := sqlerrm;
       end;	  	    
       
       if l_err_msg_tmp IS NULL then
         l_processed_count := l_processed_count + 1;  
       else
         l_rejected_count := l_rejected_count + 1;
         l_err_msg := l_err_msg_tmp; 
       end if;
   end loop;
   
   if l_rejected_count = 0 then
   	 commit;
   else
     rollback;
   end if;
   
   -- insert into log table
   insert into capcnv_log ( prog_id,process_date, record_processed,record_rejected,record_extracted,err_msg) 
    values ('CAPPOIMP_ITEM_B', sysdate, l_processed_count, l_rejected_count, l_processed_count-l_rejected_count, l_err_msg );
   
   commit;
exception 
  when others then
    dbms_output.put_line(sqlerrm);
    rollback;  
end;
/


--exit
